{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @copyright 2003-2014 by the INDEPNET Development Team.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{# @var form                   Glpi\Form #}
{# @var section                Glpi\Form\Section|null #}
{# @var section_index          int|null #}
{# @var question_types_manager QuestionTypesManager #}
{# @var can_update             bool #}
{# @var show_section_form      bool #}
{# @var number_of_sections     int #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{# Common params for any fields #}
{% set base_field_options = {
    'is_horizontal': false,
    'full_width'   : true,
    'no_label'     : true,
} %}

<section
    data-glpi-form-editor-section
    data-glpi-form-editor-condition-type="{{ enum('Glpi\\Form\\ConditionalVisiblity\\Type').SECTION.value }}"
    class="mt-4"
    aria-label="{{ __("Form section") }}"
>
    <div
        class="bg-primary px-2 py-1 rounded-top {{ show_section_form ? "" : "d-none" }}"
        style="width: fit-content;"
        data-glpi-form-editor-section-number-display
    >
        {{ __("Step %d of %d")|format(section_index, number_of_sections) }}
    </div>

    <section
        aria-label="{{ __("Section details") }}"
        data-glpi-form-editor-section-details
        data-glpi-form-editor-on-click="set-active"
        class="{{ show_section_form ? "" : "d-none" }}"
    >
        <div
            class="card"
            style="border-top-left-radius:0;"
        >
            <div
                class="card-status-start bg-primary"
                data-glpi-form-editor-active-section-status-indicator
            ></div>
            <div class="card-body">
                {# Header #}
                <div class="d-flex align-items-center">
                    {# Section's name #}
                    <input
                        title="{{ __("Section name") }}"
                        type="text"
                        class="form-control content-editable-h2 mb-0"
                        name="name"
                        value="{{ section is not null ? section.fields.name : '' }}"
                        placeholder="{{ __("New section") }}"
                        data-glpi-form-editor-section-details-name
                        data-glpi-form-editor-dynamic-input
                        data-glpi-form-editor-on-input="compute-dynamic-input"
                    />

                    {# Visibility dropdown #}
                    {{ include('pages/admin/form/conditional_visibility_dropdown.html.twig', {
                        'item': section,
                        'type': "Glpi\\Form\\Section",
                    }, with_context = false) }}

                    {# Collapse section #}
                    <i
                        role="button"
                        class="ti ti-selector ms-3 cursor-pointer"
                        data-bs-toggle="tooltip"
                        data-bs-placement="top"
                        title="{{ __("Collapse section") }}"
                        data-glpi-form-editor-on-click="collapse-section"
                    ></i>

                    {# Extra actions #}
                    <div class="dropdown ms-3 cursor-pointer d-flex align-items-center">
                        <i
                            class="ti ti-dots-vertical show"
                            data-bs-toggle="dropdown"
                            aria-expanded="false"
                            role="button"
                            title="{{ __('More actions') }}"
                        ></i>
                        <ul class="dropdown-menu" data-bs-popper="none">
                            <li>
                                <button
                                    type="button"
                                    class="dropdown-item"
                                    data-glpi-form-editor-on-click="duplicate-section"
                                >
                                    <i class="ti ti-copy me-2"></i>
                                    <span>{{ __("Duplicate section") }}</span>
                                </button>
                            </li>
                            <li>
                                <button
                                    type="button"
                                    class="dropdown-item"
                                    data-bs-toggle="modal"
                                    data-bs-target="[data-glpi-form-editor-move-section-modal]"
                                    data-glpi-form-editor-on-click="build-move-section-modal-content"
                                >
                                    <i class="ti ti-arrows-move-vertical me-2"></i>
                                    <span>{{ __("Move section") }}</span>
                                </button>
                            </li>
                            <li>
                                <button
                                    type="button"
                                    class="dropdown-item {{ section_index == 1 ? "d-none" : "" }}"
                                    aria-label="{{ __('Merge with previous section') }}"
                                    data-glpi-form-editor-on-click="merge-with-previous-section"
                                >
                                    <i class="ti ti-arrow-merge me-2"></i>
                                    <span>{{ __("Merge with previous section") }}</span>
                                </button>
                            </li>

                            <li>
                                <button
                                    type="button"
                                    class="dropdown-item"
                                    data-glpi-form-editor-on-click="delete-section"
                                >
                                    <i class="ti ti-trash me-2"></i>
                                    <span>{{ __("Delete section") }}</span>
                                </button>
                            </li>

                            <li>
                                <button
                                    type="button"
                                    class="dropdown-item"
                                    data-glpi-form-editor-on-click="show-visibility-dropdown"
                                >
                                    <i class="ti ti-eye-cog me-2"></i>
                                    <span>{{ __("Configure visiblity") }}</span>
                                </button>
                            </li>
                        </ul>
                    </div>
                </div>

                {# Section's description #}
                <div
                    class="content-editable-tinymce mt-3"
                    data-glpi-form-editor-section-description
                >
                    {{ fields.textareaField(
                        "description",
                        section is not null ? section.fields.description : '',
                        __('Header'),
                        base_field_options|merge({
                            'enable_richtext': true,
                            'placeholder': __('Add a description to this section...'),
                            'aria_label': __('Section description'),
                            'add_body_classes': ['content-editable-tinymce-editor', 'text-muted'],
                            'editor_height': "0",
                            'rows' : 1,
                            'toolbar_location': 'bottom',
                            'init': section is not null ? true : false,
                            'mb': 'mb-0',
                        })
                    ) }}
                </div>

                <input
                    type="hidden"
                    name="uuid"
                    value="{{ section is not null ? section.fields.uuid : '' }}"
                />
                <input
                    type="hidden"
                    name="forms_forms_id"
                    value="{{ form.fields.id }}"
                />
                <input
                    type="hidden"
                    name="rank"
                    value="{{ section is not null ? section.fields.rank : 0 }}"
                />
            </div>
        </div>

        <div data-glpi-form-editor-section-extra-details>
            {{ include('pages/admin/form/form_toolbar.html.twig', {
                'can_update'     : can_update,
                'form'           : form,
                'vertical_layout': false,
            }, with_context = false) }}
        </div>

    </section>

    <div data-glpi-form-editor-section-blocks class="mt-3">
        {% for form_group_blocks in section.getBlocks() %}
            {% if form_group_blocks is iterable %}
                {{ include('pages/admin/form/form_horizontal_block.html.twig', {
                    'blocks'         : form_group_blocks,
                    'can_update'     : can_update,
                    'form'           : form,
                }, with_context = false) }}
            {% else %}
                {% set form_block = form_group_blocks %}
                {{ form_block.displayBlockForEditor() }}
            {% endif %}
        {% endfor %}
    </div>

</section>

